from pprint import pprint

# 第一问
classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
# l = sorted(classes,key=lambda x:x['grade'])
# 根据grade进行排序
classes.sort(key=lambda x: x['grade'])
pprint(classes)
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

# 通过filter语句来筛选出Grade为A的同学
f = filter(lambda x: True if x["grade"] == "A" else False, classes)
pprint(list(f))
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")


# 第三问 age加1
def add(n):
    n["age"] += 1
    return n


m = map(add, classes)
pprint(list(m))
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")


# 递归函数构造斐波那契数列


def f(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return f(n - 2) + f(n - 1)


for n in range(10):
    print(f(n))
